
#include "stdio.h"
#include <stdint.h>
#include "../section_locate.h"
#include "pt-thread.h"
#include "my_utils.h"
#include <math.h>
#include "algorithm_collector.h"


static void polyfit_test(void);
PLACE_FUNC_AT_SEC(polyfit_test);


static double x[] = {18, 22, 26};
static double y[] = {1364, 1546, 1484};


// tesla 速度时刻数据
//static double x[] = {21.35, 22.36, 23.38, 24.4, 25.41, 26.43, 27.45 };
//static double y[] = {119, 118.5, 116, 109.5, 94, 74, 48.5};
// tesla 制动压力时刻数据
//double x[] = {23.24, 23.46, 23.66, 23.87, 24.08, 24.28, 24.49, 24.7, 24.91, 25.11, 25.32, 25.53, 25.74, 25.95, 26.16, 26.37, 26.58, 26.79, 27, 27.21, 27.42, 27.63};
//double y[] = {0.3, 4.5, 6, 7.5, 11.4, 12.3, 18.3, 24.6, 25.8, 30.9, 40.2, 41.4, 45.9, 61.2, 73.2, 92.7, 86.1, 101.7, 114.9, 111, 130.98, 140.7};

DEFINE_POLYFIT(my_polyfit, SIZEOF_ARR(x), 2);
static void polyfit_test(void)
{
    double a[2 + 1];

    my_polyfit_$polyfit(x, y, a);

    for(int i = 0; i < 2; i++){
        printf("a[%d] = %f\n", i, a[i]);
    }

    uint32_t max_pos = -a[1] / (2 * a[2]);
    printf("max_pos = %u\n", max_pos);
}
